﻿@{
    Layout = null;
}
@using Kevin.Shop.Business.Service.Entity.Helper
@model RiderShop.Mobile.Modle.Purchase.GreetingOrderModel
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>亲爱的 @Model.OrderGreetingCardInfo.RecipientName，您的小伙伴 @Model.OrderGreetingCardInfo.CustomerUserName 送您了一份大礼，快来领取吧</title>
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
    <link rel="stylesheet" href="~/Themes/RongJi/Style/greetingcard/js/joyride-2.1.css">
    <link rel="stylesheet" href="~/Themes/RongJi/Style/greetingcard/css/app.css">
    <link href="~/Themes/Common/assert/plugins/sweetalert-1.0/lib/sweet-alert.css" rel="stylesheet" />
</head>
<body>

    <div class="cardBody @Request.QueryString["CardId"]">
        <div class="audioPlayer">
            <a href="~/Themes/RongJi/Style/greetingcard/audio/@Html.Raw(@Request.QueryString["CardId"] + ".mp3")" title="" class="sm2_button"></a>
        </div>
        <div class="center">
            @if (Model.OrderInfo.RegionId > 0)
            {
                <button id="setAddress" status="true">等待惊喜降临</button>
            }
            else
            {
                <button id="setAddress" status="false">接收礼品</button>
            }
        </div>
        <div class="texts">
            <div class="to">@Model.OrderGreetingCardInfo.RecipientName</div>
            <div class="greetings">@Model.OrderGreetingCardInfo.Content</div>
            <div class="from">@Model.OrderGreetingCardInfo.CustomerUserName</div>
        </div>
        <div class="diyTool">
            @if (WebClientContext.Current != null && WebClientContext.Current.UserId == Model.OrderInfo.CustomerUserId)
            {
                <button id="sendIt">发送</button>
                <button id="goBack" onclick="history.go(-1)">发送</button>
            }
        </div>
    </div>
    <div class="sendTips"></div>
    <div class="diyBox">
        <form class="form-horizontal" action="~/Purchase/AddGreetingAddress" method="post" id="formAddGreetingAddress">
            <input type="hidden" name="OrderNumber" value="@Request.QueryString["OrderNumber"]" />

            <div class="diyBoxInner">
                <label>收礼人姓名</label>
                <input name="CustomerUserName" id="CustomerUserName" type="text" maxlength="6" placeholder="收礼人姓名">
                <label>联系电话</label>
                <input name="ReceiveCellPhone" id="ReceiveCellPhone" type="text" maxlength="11" placeholder="联系电话">
                <label>收货地址</label>
                <input type="hidden" name="RegionId" id="RegionId">
                <fieldset>
                    @*<select id="region" name="region" class="select">
                        <option value="" selected="selected">省份</option>*@
                    @if (Model.OrderInfo.CustomerUserName == "外地礼品订单")
                    {
                        <select id="region" name="region" class="select">
                            <option value="" selected="selected">省份</option>
                            @foreach (var item in RiderShop.Mobile.Modle.MyAccount.MyAccountModel.GetRegionListByParentId(0))
                            {
                                <option value="@item.RegionId">@item.RegionName</option>
                            }
                        </select>
                        <select id="city" name="city" class="select">
                            <option value="0">城市</option>
                        </select>
                        <select id="county" name="county" class="select">
                            <option value="0">区县</option>
                        </select>
                    }
                    else if (Model.OrderInfo.CustomerUserName == "本地礼品订单")
                    {
                        var selectedProvince = -999;
                        var selectedCity = -999;
                        <select id="region" name="region" class="select" disabled>
                            <option value="" selected="selected">省份</option>
                            @foreach (var item in RiderShop.Mobile.Modle.MyAccount.MyAccountModel.GetRegionListByParentId(0))
                            {
                                if (item.RegionName == "陕西省")
                                {
                                    selectedProvince = @item.RegionId;
                                    <option value="@item.RegionId"  selected>@item.RegionName</option>
                                }
                            }
                        </select>
                        if (selectedProvince != -999)
                        {
                            <select id="city" name="city" class="select" disabled>
                                <option value="0">城市</option>
                                @foreach (var item in RiderShop.Mobile.Modle.MyAccount.MyAccountModel.GetRegionListByParentId(selectedProvince))
                                {
                                    if (item.RegionName == "西安市")
                                    {
                                        selectedCity = @item.RegionId;
                                        <option value="@item.RegionId"  selected>@item.RegionName</option>
                                    }
                                }
                            </select>
                        }
                        if (selectedCity != -999)
                        {
                            <select id="county" name="county" class="select">
                               <option value="0" selected>区县</option>
                                @foreach (var item in RiderShop.Mobile.Modle.MyAccount.MyAccountModel.GetRegionListByParentId(selectedCity))
                                {
                                    <option value="@item.RegionId">@item.RegionName</option>
                                }
                            </select>
                        }
                    }

                    <textarea name="ReceiveAddress" id="ReceiveAddress" maxlength="60" class="form-control bmargin" rows="3" placeholder="请填写收货人详细地址(街道、小区、门牌号)"></textarea>
                </fieldset>
                <div class="btn-groups">
                    <button class="btn btnCancel" onclick="return false">取消</button>
                    <button class="btn btnSubmit" id="btnPreview" type="button">确认</button>
                </div>
            </div>
        </form>

    </div>
    @if (WebClientContext.Current != null && WebClientContext.Current.UserId == Model.OrderInfo.CustomerUserId)
    {
        <ol id="joyRideTipContent">
            <li data-id="sendIt" data-text="关闭">
                <h2>发送贺卡</h2>
                <p>分享此页面给您的亲朋好友</p>
            </li>
        </ol>
    }
    else
    {
        if (Model.OrderInfo.RegionId <= 0)
        {
        <ol id="joyRideTipContent">
            <li data-id="setAddress" data-text="关闭">
                <h2>领取礼品</h2>
                <p>您的好友送了一份礼物给你快来收礼吧</p>
            </li>
        </ol>
        }
    }

    <script type="text/javascript" src="~/Themes/RongJi/Style/greetingcard/js/jquery.min.js"></script>
    <script type="text/javascript" src="~/Themes/RongJi/Style/greetingcard/js/soundmanager2-jsmin.js"></script>
    <script type="text/javascript" src="~/Themes/RongJi/Style/greetingcard/js/jquery.joyride-2.1.js"></script>
    <script type="text/javascript" src="~/Themes/RongJi/Style/greetingcard/js/app.js"></script>
    <script type="text/javascript" src="~/Utility/pages/pg_common.js"></script>
    <script type="text/javascript" src="~/Utility/pages/regionselect.js"></script>
    <script src="~/Themes/Common/assert/plugins/sweetalert-1.0/lib/sweet-alert.js" charset="gb2312"></script>

    <script src="~/Themes/RongJi/Style/base/js/weixinshare.js"></script>
    <script type="text/javascript">
        window.config = {
            link: '@Html.Raw(string.Format("http://{0}/Purchase/PreviewCardGreetingCard?orderNumber={1}&cardId={2}", Request.Url.Authority, Request.QueryString["ordernumber"], Request.QueryString["cardid"]))',
            imgUrl: 'http://m.rongji365.com/staticResource/imgs/wish_icon.jpg',
            img_url: 'http://m.rongji365.com/staticResource/imgs/wish_icon.jpg',
            title: '您的小伙伴给您送礼了',
            desc: '亲爱的 @Model.OrderGreetingCardInfo.RecipientName，您的小伙伴 @Model.OrderGreetingCardInfo.CustomerUserName 送您了一份大礼，快来领取吧'
        };
    </script>
    @Html.Action("ConfigScript", "WeixinJsSdk")
</body>
</html>

<script>
    $(window).load(function () {
        $('#joyRideTipContent').joyride({
            autoStart: true,
            postStepCallback: function (index, tip) {
                if (index == 2) {
                    $(this).joyride('set_li', false, 1);
                }
            },
            modal: true,
            expose: true
        });
    });
</script>

<script>
    $(function () {
        var mutiSub = false;

        $('#setAddress').click(function () {
            if ($('#setAddress').attr('status') === 'false') {
                $('.diyBox').show();
            }
            else {
                //KevinShop.MessageBox.Alert('收礼地址已设置，请等待收货。');
            }
        });


        $('#btnPreview').on('click', function () {
            if (mutiSub) {
                return false;
            }
            var $shipTo = $.trim($("#CustomerUserName").val());
            var $cellPhone = $.trim($("#ReceiveCellPhone").val());
            var $regionId = $("#RegionId").val();
            var $address = $.trim($("#ReceiveAddress").val());

            if ($shipTo == "") {
                KevinShop.MessageBox.Alert('请输入收货人');
                return false;
            }
            if ($cellPhone == "") {
                KevinShop.MessageBox.Alert('请输入手机号码');
                return false;
            }

            var reg = /^(\+\d{2,3}\-)?\d{11}$/;
            if (!reg.test($cellPhone)) {
                KevinShop.MessageBox.Alert('请输入正确的手机号码');
                return false;
            }
            if ($regionId == "") {
                KevinShop.MessageBox.Alert('请选择地区');
                return false;
            }

            if ($address == "") {
                KevinShop.MessageBox.Alert('请输入收货地址');
                return false;
            }

            var postData = $('#formAddGreetingAddress').serialize();
            var formURL = $('#formAddGreetingAddress').attr("action");
            mutiSub = true;
            $.ajax({
                type: "POST",
                url: formURL,
                dataType: "JSON",
                data: postData,
                success: function (response) {
                    mutiSub = false;
                    if (response) {
                        alert(response);
                    }
                    else {
                        KevinShop.MessageBox.Alert("填写成功，请等待惊喜降临。");
                        $('#setAddress').attr('status', true);
                        $('#setAddress').html('等待惊喜降临');

                        $('#btnPreview').prop('disabiled', true);

                        var box = $('.diyBox');
                        var card = $('.cardBody');
                        box.fadeOut();
                        card.removeClass('blurIt');
                    }
                },
                error: function (err) {
                    mutiSub = false;
                    alert(err.responseText);
                    return;
                }
            });
            return false;

        });
    });
</script>
